package business

import (
	"fcs-api/src/app/model"
	"fcs-api/src/app/service/ksvc"
	k8s "fcs-api/src/client/kubernetes"
)

func GetVersionList(functionId string) ([]*model.FuncVersion, error) {
	versionList, err := model.GetVersionList(functionId)
	if err != nil {
		_ = logger.Error("GetVersionList: get list from db error, %s", err.Error())
		return nil, err
	}
	return versionList, nil
}

func DeleteVersion(fcClient *k8s.FcClient, funcInfo *model.FuncInfo, token string) error {
	//if funcInfo.EnableVpc == 1 {
	//	go func() {
	//		err := removeVpcConfig(fcClient, funcInfo, &funcInfo.VpcInfo, token)
	//		if err != nil {
	//			_ = logger.Error("DeleteVersion: remove vpc config error")
	//		}
	//	}()
	//}
	err := ksvc.DeleteVersion(fcClient, funcInfo)
	if err != nil {
		_ = logger.Error("DeleteVersion: delete ksvc version error %s", err.Error())
		return err
	}
	err = model.DeleteVersion(funcInfo.Id, funcInfo.VersionName)
	if err != nil {
		_ = logger.Error("DeleteVersion: delete version database error %s", err.Error())
		return err
	}
	return nil
}
